package com.longway.core.toolbox.dd.api;
/*package com.longway.core.toolbox.dd.api;

import java.util.concurrent.Callable;

import com.longway.core.toolbox.cache.ICache;
import com.longway.core.toolbox.utils.RetryUtils;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiUserGetRequest;
import com.dingtalk.api.request.OapiUserGetuserinfoRequest;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.dingtalk.api.response.OapiUserGetuserinfoResponse;
import com.jfinal.kit.StrKit;

public class DingUserInfoApi {
    private static final String cachePrefix = "ding:userinfo:";
    
    *//**
     * 
     * @param code 免登陆授权码
     * @return
     *//*
    public static String getUserId(String code){
    	DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getuserinfo");
    	OapiUserGetuserinfoRequest request = new OapiUserGetuserinfoRequest();
    	request.setCode(code);
    	request.setHttpMethod("GET");
    	ApiResult result = null;
        try {
  			    result = RetryUtils.retryOnException(3, new Callable<ApiResult>() {
  	            @Override
  	            public ApiResult call() throws Exception {
  	            	OapiUserGetuserinfoResponse response = client.execute(request, DingAccessTokenApi.getAccessTokenStr());
  	    			String json = response.getBody();
  	                return new ApiResult(json);
  	            }
  	        });
  		} catch (Exception e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		}
        if(result != null && result.isSucceed()){
        	return result.getStr("userid");
        }
        return result.getStr("errmsg");
        
    }
    

    public static ApiResult getUserInfo(String code) {
        ICache cache = ApiConfigKit.getCache();
        String userId = getUserId(code);
        String userJson = cache.get(cachePrefix + userId);
        if (StrKit.notBlank(userJson)){
            return  new ApiResult(userJson);
        }else{
        	return refreshUserInfo(userId);
        }
    }

    *//**
     * 无条件强制更新用户信息
     * @param ApiConfig
     * @return ApiResult
     *//*
    private static ApiResult refreshUserInfo(String userId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get");
        OapiUserGetRequest request = new OapiUserGetRequest();
        request.setUserid(userId);
        request.setHttpMethod("GET");
        ApiResult result = null;
        try {
			    result = RetryUtils.retryOnException(3, new Callable<ApiResult>() {
	            @Override
	            public ApiResult call() throws Exception {
	            	OapiUserGetResponse response = client.execute(request, DingAccessTokenApi.getAccessTokenStr());
	    			String json = response.getBody();
	                return new ApiResult(json);
	            }
	        });
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        if (null != result && result.isSucceed()) {
            ICache cache = ApiConfigKit.getCache();
            cache.set(cachePrefix + userId, result.toString());
        }
        return result;
    }

}
*/